#include "graph.h"
#include <bits/stdc++.h>
using namespace std;

const int maxn = 205;
int dis[maxn][maxn], ans[205];
vector<pair<int, int>> vec[maxn];
int n = 1, fa[maxn], ff[maxn][maxn];
void dfs(int now, int fa)
{
    int tmp = LastRoad(), deg = NumberOfRoads();
    ::fa[now] = tmp;
    if (fa) vec[now].emplace_back(fa, tmp), dis[now][fa] = dis[fa][now] = 1;
    for (int i = 1; i <= deg; i++)
        if (i != tmp)
        {
            Move(i, 2);
            if (Color() == 1)
            {
                vec[now].emplace_back(++n, i);
                dfs(n, now);
            }
            else Move(LastRoad(), 2);
        }
    if (~tmp) Move(tmp, 2); 
}
void ga(int now, int fa, int to)
{
    if (Color() == 3) dis[now][to] = dis[to][now] = 1;
    int tmp = LastRoad();
    for (auto i : vec[now])
        if (i.second != fa)
        {
            Move(i.second, Color());
            ga(i.first, LastRoad(), to);
        }
    if (now != to)
        Move(tmp, Color());
}
void gt(int now)
{
    int deg = NumberOfRoads(), tmp = LastRoad();
    if (deg != vec[now].size())
    {
        for (int i = 1; i <= deg; i++)
            if (!ff[now][i])
            {
                Move(i, 2);
                Move(LastRoad(), 3);
            }
        ga(now, tmp, now);
        for (int i = 1; i <= deg; i++)
            if (!ff[now][i])
            {
                Move(i, 2);
                Move(LastRoad(), 2);
            }
    }
    for (auto i : vec[now])
        if (i.second != fa[now])
        {
            Move(i.second, 2);
            gt(i.first);
        }
    if (~tmp) Move(tmp, 2);
}
void Inspect(int R)
{
    memset(dis, 0x3f, sizeof(dis));
    dfs(1, 0);
    for (int i = 1; i <= n; i++)
        for (auto j : vec[i])
            ff[i][j.second] = 1;
    gt(1);
    for (int i = 1; i <= n; i++) dis[i][i] = 0;
    for (int k = 1; k <= n; k++)
        for (int i = 1; i <= n; i++)
            for (int j = 1; j <= n; j++)
                dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]);
    for (int i = 1; i <= n; i++)
        for (int j = i + 1; j <= n; j++)
            ans[dis[i][j]]++;
    for (int i = 1; i <= R; i++) Answer(i, ans[i]);
}
